
<form role="form" class="epii" method="post" data-form="1" action="{url card add_edit }">

    <div class="form-group">
        <label><span style="color: red">*</span>手机号：</label>
        <input type="text" class="form-control" name="r[phone]" id="phone" {if isset($id)}readonly{/if} value="{? $info.phone}" required
               placeholder="请输入会员手机号">
    </div>
    <div class="form-group">
        <label><span style="color: red">*</span>姓名：</label>
        <input type="text" class="form-control" id="real_name" name="r[real_name]" {if isset($id)}readonly{/if} value="{? $info.real_name}" required
               placeholder="请输入会员姓名">
    </div>
    <div class="form-group">
        <label><span style="color: red">*</span>性别：</label>
        <select class="selectpicker" name="r[sex]" id="sex">
            {:options,$sex,$info.sex}
        </select>
    </div>
    <div class="form-group">
        <label><span style="color: red">*</span>卡分类：</label>
        <select class="selectpicker" name="r[card_cate_id]" id="card_cate_id"  {if isset($id)}disabled{/if} >
            {:options,$cardCate,$info.card_cate_id}
        </select>
    </div>
    {if !isset($id)}
    <div class="form-group">
        <label>充值金额：</label>
        <input type="number" class="form-control" name="r[recharge_money]"  value=""
               placeholder="请输入充值金额" id="recharge">
    </div>
    <div class="form-group">
        <label>赠送金额：</label>
        <input type="number" class="form-control" name="r[gift_money]"  value=""
               placeholder="请输入充值金额" autocomplete="off" id="gift_money" required>
    </div>
    {/if}

    <div class="form-group">
        <label>状态：</label>
        <select class="selectpicker" name="r[status]" id="">
            {:options,$status,$info.status?1}
        </select>
    </div>
    <input type="hidden" name="id" value="{$id?0}">
    <div class="form-footer">
        <button type="submit" class="btn btn-primary">提交</button>
    </div>
</form>
<script src="{$laydate}/laydate.js"></script>
<script type="text/javascript">

    window.onEpiiInit(function() {
        $('#phone').change(function () {
            let phone=$(this).val();
            if (phone.length==11){
                var loading=layer.load(1);
                $.ajax({
                    url: '?app=card@getMemberInfo&phone='+phone,
                    type: 'get',
                    dataType:'json',
                    success: function(res) {
                        if(res.code==1){
                            console.log(res.data)
                            $('#real_name').val(res.data.real_name);
                            $('#sex').val(res.data.sex);
                            $('#sex').selectpicker('refresh');;
                            // $('#real_name').attr('readonly',true);
                        }
                        layer.close(loading)
                    }
                });
                // layer.close(loading)
            }
        });

        $('#gift_money').focus(function () {
            let recharge_money=$('#recharge').val();
            let card_cate_id=$('#card_cate_id').val();
            console.log(recharge_money)
            console.log(card_cate_id)
            if (recharge_money.length==0){
                layer.msg('请填写充值金额');
                return;
            }
            if(card_cate_id==''){
                layer.msg('请先选择卡分类');
                return;
            }
            var loading=layer.load(1);
            $.ajax({
                url: '?app=card@getGiftMoney&recharge_money='+recharge_money+'&card_cate_id='+card_cate_id,
                type: 'get',
                dataType:'json',
                success: function(res) {
                    if(res.code==1){
                        $('#gift_money').val(res.data.gift_money);
                    }
                    layer.close(loading)
                }
            });
            // layer.close(loading)
        });
    });

</script>
